$(document).ready(function() {
	view_init();
	event_init();
});

function view_init() {
	loadingStart();

	$("[data-type=dateAll]").each(
			function() {
				$(this).datetimepicker(
						{
							timeFormat : "HH:mm:ss",
							dateFormat : "yy-mm-dd",
							monthNames : [ "一月", "二月", "三月", "四月", "五月", "六月",
									"七月", "八月", "九月", "十月", "十一月", "十二月" ]
						});
			});

	list_list(true);

	$("#main-content").show();
}

function event_init() {
	// 查询按钮
	$("#query").click(function() {
		$("#list_tbody").html("");
		list_list(true);
	});

	// 详情按钮
	$("#list_tbody").delegate("[data-id=edit]", "click", function() {
		var a = $(this).parent().attr("data-id");
		$('body').umDialog("alert", {
			content : a,
			width : 450,
			left : "40%",
			top : "23%"
		});
	});

	// 翻页事件
	index_initPageEvent("list_list()");
}

function list_list(isFirst) {
	if (isFirst) {
		index_pageObj.init();
	}

	loadingStart();

	var obj = $("#query_panel").umDataBind("serialize", "");
	obj.currentPage = index_pageObj.currentPage;
	obj.pageSize = index_pageObj.pageSize;

	um_ajax_post(INDEX_WEBAPP + "/webuser/select.do", obj, function(data) {
		$("#page_record_count").text(data.size);
		_render(data.webusers);
	}, null);
	function _render(data) {
		var buffer = [];
		if (data && data.length > 0) {
			for ( var i = 0; i < data.length; i++) {
				buffer.push('<tr>');
				buffer.push('<td>' + data[i].id + '</td>');
				buffer.push('<td>' + data[i].phone + '</td>');
				buffer.push('<td>' + data[i].userName + '</td>');
				buffer.push('<td>' + beautyNull(data[i].registerDate)
								+ '</td>');
				buffer.push('<td style="text-align: center" data-id="'
								+ data[i].comment
								+ '"><a href="#" data-id=edit>查看</a>');
				buffer.push('<tr>');
			}
			$("#list_tbody").html(buffer.join(""));
		} else {
			index_pageObj.toEndPage();
		}

		index_pageObj.isEndMethod(data);

	}
}
